package com.gycode.vpush.controller;


import com.alibaba.fastjson.JSONObject;
import com.gycode.vpush.dto.base.ResultDTO;
import com.gycode.vpush.dto.request.SendMessageDTO;
import com.gycode.vpush.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lgy
 *
 */
@Slf4j
@RestController
@RequestMapping("/message")
public class MessageController {


    @Autowired
    private MessageService webSocketService;

    @PostMapping("/push")
    public ResultDTO sendMessage(@RequestBody @Validated SendMessageDTO webSocketMsgDTO) {
        log.info("接收到预推送的消息为 {}", JSONObject.toJSONString(webSocketMsgDTO));
        ResultDTO resultDTO = webSocketService.sendMessage(webSocketMsgDTO);
        log.info("响应的数据为 {}",JSONObject.toJSONString(resultDTO));
        return resultDTO;
    }

}
